using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using CustomSecurity;

namespace Portal
{
    public partial class UcPhanHe : UserControl
    {
        public delegate void CallFunctionHandler(object caller, string function);
        public event CallFunctionHandler CallFunction;

        public UcPhanHe()
        {
            InitializeComponent();
        }

        protected void Call(string function) {
            if (CallFunction != null)
            {
                CallFunction(this, function);
            }
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            Call("UcTongThe");
        }

        public virtual void ShowHideFunction()
        {
            if (User.CurUser == null)
            {
                pnBackground.Enabled = false;
                return;
            }
            else {
                pnBackground.Enabled = true;
                foreach (Control control in this.pnBackground.Controls)
                {
                    if (control is FlowLayoutPanel)
                    {
                        foreach (Control btnControl in (control as FlowLayoutPanel).Controls)
                        {
                            if (btnControl is Button && (btnControl.Tag is string))
                            {
                                Function function = FunctionList.GetByName(btnControl.Tag as String);
                                if (function == null) 
                                    continue;
                                else 
                                    btnControl.Visible = (function.PosibleRight & User.CurUser.GetRight(function.ID)) > 0;
                            }
                        }
                    }
                }
            }
        }
    }
}
